/* SpanTreeMsg.h
 * Authors : Mayank Mishra, Prabhakar Ekde,   CSE IIT-Bombay
 */

#ifndef SPANTREEMSG_H
#define SPANTREEMSG_H

#define ST_GENERIC_MSG_OVERHEAD     4
#define ST_BEACON_MSG_OVERHEAD      (ST_GENERIC_MSG_OVERHEAD + 2)
#define HB_MSG_OVERHEAD             (ST_GENERIC_MSG_OVERHEAD + 1)
#define DATA_MSG_OVERHEAD           (ST_GENERIC_MSG_OVERHEAD + 2)
#define REC_ROUTE_DATA_MSG_OVERHEAD (DATA_MSG_OVERHEAD + 1)
#define TOPO_INFO_DATA_MSG_OVERHEAD (DATA_MSG_OVERHEAD + 3)

#define MAX_PKT_SIZE 25

typedef enum {
    DATA_MSG = 0,
    ST_BEACON,
    HB_MSG,
    POISON_MSG,
    RELN_REQ,
    RELN_RESP_SUCCESS,
    RELN_RESP_FAILURE
} SpanTreeMsgType;


/* Spanning Tree Basic Generic Message. This message defines the overall packet format. */
typedef nx_struct SpanTreeGenericMsg {
    nx_uint8_t nodeId;
    nx_uint8_t msgType;
    nx_uint16_t msgLen;
    nx_uint8_t msgPayload[0];
} SpanTreeGenericMsg;


/* Here we need to define the kinds of messages SpanTree protocol will use */

/* CONTROL MESSAGES */

/* SpanTree Beacon Message */
/* Broadcasted by nodes which are ready to accept children. Ie which have found a parent. */
typedef nx_struct SpanTreeSTBeaconMsg {
    /* The ordered list for all ancestor nodes from root */
    nx_uint8_t pathVectorLength;
    
    /* The list of all children */
    nx_uint8_t numChildren;
    nx_uint8_t list[0];
} SpanTreeSTBeaconMsg;

/* SpanTree Heart Beat Message */
/* Sent from child to parent to inform child's activity */
typedef nx_struct SpanTreeHBMsg {
    /* The list of all routes -- acts as routing message 
     * update from child to parent
     */
    nx_uint8_t numRoutes;
    nx_uint8_t routeList[0];
} SpanTreeHBMsg;

/* DATA MESSAGE */

typedef enum {
    DATA_INFO_PAYLOAD = 0,
    DATA_REC_ROUTE_PAYLOAD    
} SpanTreeDataPayloadType;

typedef nx_struct SpanTreeDataMsg {
    nx_uint8_t destId;
    nx_uint8_t payloadType;
    nx_uint8_t payload[0];
} SpanTreeDataMsg;

/* DATA Message with record route*/
typedef nx_struct SpanTreeRecRoutePayload {
    nx_uint8_t numRouteHops;
    nx_uint8_t routeHops[0];
} SpanTreeRecRoutePayload;

/* DATA Message with Local Topology info */
typedef nx_struct SpanTreeInfoPayload {
    nx_uint8_t parentId;
    nx_uint8_t numChildren;
    nx_uint8_t numRouteEntries;
    nx_uint8_t list[0];
} SpanTreeInfoPayload;

#endif

